package com.ruoyi.source.controller;

import java.util.List;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.source.api.domain.SrcInStore;
import com.ruoyi.source.domain.vo.SrcCropInStoreVo;
import com.ruoyi.source.domain.vo.SrcInStoreVo;
import com.ruoyi.source.service.ISrcInStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import springfox.documentation.spring.web.json.Json;

/**
 * 入库Controller
 * 
 * @author ruoyi
 * @date 2024-07-27
 */
@RestController
@RequestMapping("/in/store")
public class SrcInStoreController extends BaseController {
    @Autowired
    private ISrcInStoreService srcInStoreService;

    /**
     * 查询入库列表
     */
    @RequiresPermissions("source:in:list")
    @GetMapping("/list")
    public TableDataInfo list(SrcInStore srcInStore) {
        startPage();
        List<SrcInStoreVo> list = srcInStoreService.selectSrcInStoreList(srcInStore);
        return getDataTable(list);
    }

    /**查询所有农作物入库列表(下拉框)*/
    @GetMapping("/get/crop")
    public TableDataInfo getCropInStoreList(){
        List<SrcCropInStoreVo> cropInStoreList = srcInStoreService.getCropInStoreList();
        return getDataTable(cropInStoreList);
    }

    /**查询所有入库列表(下拉框)*/
    @GetMapping("/get/in/store/list")
    public TableDataInfo getInStoreList(){
        List<SrcCropInStoreVo> cropInStoreList = srcInStoreService.getInStoreList();
        return getDataTable(cropInStoreList);
    }
    /**
     * 导出入库列表
     */
 /*   @RequiresPermissions("source:in:export")
    @Log(title = "入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrcInStore srcInStore)
    {
        List<SrcInStore> list = srcInStoreService.selectSrcInStoreList(srcInStore);
        ExcelUtil<SrcInStore> util = new ExcelUtil<SrcInStore>(SrcInStore.class);
        util.exportExcel(response, list, "入库数据");
    }*/

    /**
     * 获取入库详细信息
     */
    @RequiresPermissions("source:in:query")
    @GetMapping(value = "/{inStoreId}")
    public AjaxResult getInfo(@PathVariable("inStoreId") Long inStoreId) {
        return success(srcInStoreService.selectSrcInStoreByInStoreId(inStoreId));
    }

    /**
     * 新增入库
     */
    @RequiresPermissions("source:in:add")
    @Log(title = "入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrcInStore srcInStore) {
        return toAjax(srcInStoreService.insertSrcInStore(srcInStore));
    }

    /**
     * 修改入库
     */
    @RequiresPermissions("source:in:edit")
    @Log(title = "入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrcInStore srcInStore) {
        return toAjax(srcInStoreService.updateSrcInStore(srcInStore));
    }

    /**
     * 删除入库
     */
    @RequiresPermissions("source:in:remove")
    @Log(title = "入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inStoreIds}")
    public AjaxResult remove(@PathVariable Long[] inStoreIds) {
        return toAjax(srcInStoreService.deleteSrcInStoreByInStoreIds(inStoreIds));
    }

    /**
     * 确认签收
     */
    @GetMapping("/sign/{inStoreId}")
    public AjaxResult handleSignFor(@PathVariable Long inStoreId){
        return toAjax(srcInStoreService.update(Wrappers.<SrcInStore>lambdaUpdate().set(SrcInStore::getStatus,"1").eq(SrcInStore::getInStoreId,inStoreId)));
    }
}
